Home:ALL Converter>Overloading Pre-processor macros for {zero, one} arguments

Overloading Pre-processor macros for {zero, one} arguments

Ask Time:2014-07-10T18:01:01         Author:Robin Eisenberg

Json Formatter

I'm making a logger class for my app in C++. This class has static members to log debug output to file. I would like to create a Macro that can be used in two ways:

LOG("Log some text")
          which calls Logger::log(std::string)

-----or-----

LOG << "Log some text" << std::endl;
          which calls Logger::getLogStream()

The goal being that including Logger.h be enough to log to file, and that it be done using the same syntax, but I'm not particularly attached to Macros if you have other suggestions. Using Boost::PP is, unfortunately, not an option.

I've looked around (see this comment), but found nothing concerning differentiating between a call to LOG and LOG(). How can I differentiate one argument from no arguments?

Author:Robin Eisenberg,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/24673651/overloading-pre-processor-macros-for-zero-one-arguments
yy